define(function(require, exports, module){
	"require:nomunge,exports:nomunge,module:nomunge";
	//异步请求
var wind_async=require('ddf_wind_async');
	
var base=require('component-base');
var history = require('component-history');
	
require('component-page');

var commitTime_BEGIN, commitTime_END,beginMoney,endMoney,bankName;

function initParameter() {
	beginMoney = "";
	endMoney = "";
	bankName = "";
	commitTime_BEGIN = "";
	commitTime_END = "";
}

/**
 * 提现记录
 */
exports.init=function(m){
	history.addHis(this,arguments);
    window.$ddf_withDrawSettle = m;
	initParameter(); // 初始化参数
	var htmlStr = "";
	htmlStr += '<div id="content-header"><div id="breadcrumb"> <a href=javascript:load("'
			+ ddf.index.index_js
			+ '") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="javascript:void(0)" class="current">提现记录</a></div></div>'; //<h1>提现记录</h1>
	htmlStr += '<div class="container-fluid">';
//	htmlStr += '<hr/>';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">';
	htmlStr += '<div id="alert-tips0" ></div>';
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"><span class="icon"><i class="icon-search"></i></span><h5>搜索条件</h5><button type="button" class="label label-success toggle">缩放</button></div>  ';
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<form class="form-horizontal">';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">申请时间：</label><div class="controls"><input class="span4 m-wrap Wdate" type="text" id="commitTime_BEGIN" onClick=WdatePicker({dateFmt:"yyyy-MM-dd",readOnly:false}) />&nbsp;&nbsp;至&nbsp;&nbsp;<input class="span4 m-wrap Wdate" type="text" id="commitTime_END" onClick=WdatePicker({dateFmt:"yyyy-MM-dd",readOnly:false}) /></div></div></div>';
	htmlStr += '</div>';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span6"><div class="control-group" id = "control-money"><label class="control-label">金额：</label><div class="controls"><input class="span4 m-wrap" type="text" id="beginMoney" />&nbsp;&nbsp;至&nbsp;&nbsp;<input class="span4 m-wrap" type="text" id="endMoney" /></div></div></div>';

	htmlStr += '<div class="span6">';
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">银行名称：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span8 m-wrap" type="text" id="bankName"/>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	
	htmlStr += '</div>';
	htmlStr += '<div class="form-actions">';
	htmlStr += '<button class="btn btn-primary" type="button" onClick=$ddf_withDrawSettle.searchWithDraw()>搜索</button>&nbsp;&nbsp;&nbsp;&nbsp;';
	htmlStr += '<button class="btn btn-info" type="button" onClick=$ddf_withDrawSettle.resetSearchParams()>重置</button>';
	htmlStr += '</div>        ';
	htmlStr += '</form>';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	// ================================表单，动态生成==========
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>提现记录表</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content nopadding dataTables_wrapper">';
	htmlStr += '<table class="table table-bordered data-table">';
	htmlStr += '<thead>';
	htmlStr += '<tr>';
	htmlStr += '<th>序号</th>';
//	htmlStr += '<th>账户</th>';
//	htmlStr += '<th>姓名</th>';
	htmlStr += '<th>申请方式</th>';
	htmlStr += '<th>申请时间</th>';
	htmlStr += '<th>金额</th>';
	htmlStr += '<th>费用</th>';
	htmlStr += '<th>状态</th>';
	htmlStr += '<th>银行</th>';
	htmlStr += '<th>收款人</th>';
	htmlStr += '<th>尾号</th>';
	htmlStr += '<th>提交银行时间</th>';
	htmlStr += '<th>银行处理结果</th>';
	htmlStr += '<th>银行处理时间</th>';
	htmlStr += '</tr>';
	htmlStr += '</thead>';
	htmlStr += '<tbody id="withDrawSettleList">';
	htmlStr += '</tbody>';
	htmlStr += '</table>';
	htmlStr += '<div id="footPageDiv0">';

	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>  ';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div> ';
	showDiv("content0");
	$("#content0").html(htmlStr);
	
	
	
	$("#beginMoney").change(function() {
		 var bgM = $("#beginMoney").val();
	     if(!isNull(bgM) && !isNumber2Decimal(bgM)){
	    	 addErrorMessage("control-money", "endMoney", "金额为数字类型");
	     }else{
	    	 clearErrorMessage("control-money");
	     }
	});
	
	$("#endMoney").change(function(){
		var edM = $("#endMoney").val();
		if(!isNull(edM) && !isNumber2Decimal(edM)){
			addErrorMessage("control-money","endMoney","金额为数字类型");
		}else{
			clearErrorMessage("control-money");
		}
	});
	
	
	
	
	getWithDrawSettleDetails(1,pageSize, commitTime_BEGIN, commitTime_END,beginMoney,endMoney,bankName);
}

/**
 * 获取提现记录详细表单
 */
function getWithDrawSettleDetails(pageNumber,pageSize, commitTime_BEGIN, commitTime_END,
		beginMoney,endMoney,bankName) {
	if($("#control-money").find("span").html()!=null){
		base.tips_error("金额为数字类型");
		return;
	}
	var params = {
		"page.pageNumber" : pageNumber,
		"page.pageSize" : pageSize,
		"commitTime_BEGIN" : commitTime_BEGIN,
		"commitTime_END" : commitTime_END,
		"beginMoney" : beginMoney,
		"endMoney" : endMoney,
		"bankName" : bankName,
	};

	base.showLoading();
	
	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.withDrawSettle.getWithDrawSettleList,params));
		
		getWithDrawSettleDetailsCallBack(data);
		
	}))().start();
}

/**
 * 提现的记录的回调函数
 * 
 * @param data
 */
function getWithDrawSettleDetailsCallBack(data) {
//	alert("长度：" + data["resultList"].length);
	if (data["code"] == 1) {

		var htmlStr = "";

		for (var i = 0; i < data["resultList"].length; i++) {
			var req_time = data["resultList"][i]["REQ_TIME"] == null?"":data["resultList"][i]["REQ_TIME"];
			var result = data["resultList"][i]["RESULT"] == null?"":data["resultList"][i]["RESULT"];
			var finshTime = data["resultList"][i]["FINISH_TIME"] == null ? "":data["resultList"][i]["FINISH_TIME"];
			htmlStr += '<tr>';
			htmlStr += '<td>' + getSequence(data["pageNumber"], i + 1)
					+ '</td>';
//			htmlStr += '<td>' + data["resultList"][i]["USER_NAME"] + '</td>';
//			htmlStr += '<td>' + data["resultList"][i]["REAL_NAME"] + '</td>';
			htmlStr += '<td>' + data["resultList"][i]["APPLY_TYPE_NAME"]
					+ '</td>';
			htmlStr += '<td>' + data["resultList"][i]["COMMIT_TIME"] + '</td>';
			htmlStr += '<td>' + parseFloat(data["resultList"][i]["AMOUNT"]) + '</td>';
			htmlStr += '<td>' + parseFloat(data["resultList"][i]["FEE"]) + '</td>';
			htmlStr += '<td>' + data["resultList"][i]["APPLY_STATUS_NAME"]
					+ '</td>';
			htmlStr += '<td>' + data["resultList"][i]["BANK_NAME"] + '</td>';
			htmlStr += '<td>' + data["resultList"][i]["ACCOUNT_NAME"] + '</td>';
			htmlStr += '<td>' + data["resultList"][i]["BANK_NUMBER"] + '</td>';
			htmlStr += '<td>' + req_time + '</td>';
			htmlStr += '<td>' + result + '</td>';
			htmlStr += '<td>'+ finshTime +  '</td>';
			htmlStr += '</tr>';
		}

		$("#withDrawSettleList").html(htmlStr);
		
		 $('#footPageDiv0').ddf_pagination(data["pageSize"],data["pageNumber"],data["totalCount"],data["totalPage"],{  
			 
			 changePageCallback:function(pageSize,page){  
				 getWithDrawSettleDetails(page,pageSize, commitTime_BEGIN, commitTime_END, beginMoney,endMoney,bankName);
			 },
			 changePageSizeCallBack:function(pageSize){
				 getWithDrawSettleDetails(1,pageSize, commitTime_BEGIN, commitTime_END, beginMoney,endMoney,bankName);
			 } 
	     }); 
		
		
	} else {
		base.tip_error(data["message"]);
	}

	base.cancelLoading();
}

/**
 * 搜索的提现记录的方法
 * @returns {Boolean}
 */
function searchWithDraw(){
	commitTime_BEGIN = $("#commitTime_BEGIN").val(); //获取开始时间
 	commitTime_END = $("#commitTime_END").val(); //获取结束时间
 	beginMoney = $("#beginMoney").val(); 
 	endMoney = $("#endMoney").val(); 
 	bankName = $("#bankName").val();
	
	if(!base.checkDate(commitTime_BEGIN,commitTime_END)){
		return;
	}
	
	if(!(beginMoney==""&&endMoney=="")){
		if(beginMoney==""){
			base.tips_error("开始金额不能为空");
			return;
		}
		if(endMoney==""){
			base.tips_error("结束金额不能为空");
			return;
		}
	}
	if(parseFloat(beginMoney)>parseFloat(endMoney)){
		base.tips_error("开始金额不能大于结束金额");
		return;
	}
	
	if($("#control-money").find("span").html()!=null){
		base.tips_error("金额为数字类型");
		return;
	}
	
	getWithDrawSettleDetails(1,pageSize, commitTime_BEGIN, commitTime_END,beginMoney,endMoney,bankName);
}


/**
 * 显示DIV
 */
function showDiv(block){
	
	$("#content > div").hide();
	
	if($("#"+block).length<=0){
		
		$("#content").append('<div id="'+block+'"></div>'); 
		
	}else{
		
		$("#"+block).show();
	}
	
	if(block=="content0"){
		shopTypeId="";
	}
	

	
}

/**
 * 重置参数
 */
function resetSearchParams() {
	beginMoney = "";
	endMoney = "";
	bankName = "";
	commitTime_BEGIN = "";
	commitTime_END = "";
	$("#beginMoney").val("");

	$("#endMoney").val("");
	
	$("#bankName").val("");

	$("#commitTime_BEGIN").val("");

	$("#commitTime_END").val("");

}





   exports.getWithDrawSettleDetails = getWithDrawSettleDetails; //获取加载体现记录
   exports.searchWithDraw = searchWithDraw; //提现搜索
   exports.showDiv =showDiv;
   exports.resetSearchParams = resetSearchParams; 
   
//   window.$ddf_withDrawSettle.
});